# name : gsDesign nSurv hr.mdd
# key : gsDesign.nSurv.hr.mdd
# expand-env: ((yas-indent-line 'fixed) (yas-wrap-around-region 'nil))
# contributor: Shuguang Sun
# --
${1:nsurv_hr_mdd} <- function (x) {
    # x from nSurv
    c <- 1/(1 + x$ratio)
    psi <- c * (1 - c)
    if (is.null(x$hr0)) {
        x$hr0 <- 1
    }
    zalpha <- -stats::qnorm(x$alpha/x$sided)
    ## zb <- (log(x$hr0/x$hr) - zalpha * sqrt(1/sum(x$eDC0) + 1/sum(x$eDE0))) /
    ##   sqrt(1/sum(x$eDC) + 1/sum(x$eDE))

    # hrHat <- exp(-zalpha/sqrt(x$d * psi)) * x$hr0
    hrHat <- exp(-zalpha * sqrt(1/sum(x$eDC) + 1/sum(x$eDE))) * x$hr0
    hrHat
}
$1(x)
